package com.example.demo.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Company;
import com.example.demo.mapper.CompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class CompanyService extends ServiceImpl<CompanyMapper, Company> {
    @Autowired
    CompanyMapper companyMapper;

    public Map<String, Object> list(int current, int size){
        IPage<Company> page = new Page<>(current, size);
        this.page(page);

        Map<String,Object> data = new HashMap<>();
        data.put("total", page.getTotal());
        data.put("list", page.getRecords());
        return data;
    }
    public Company getByIdWithProduct(long id){
        return companyMapper.selectByIdWithProduct(id);
    }
}
